package learn.web.filter;


import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created by sqluogui on 2016/9/30.
 */
public class LoginFilter extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception {
        HttpSession session =  request.getSession();
        String url = request.getRequestURI();
        if(url.contains("/checkCode") || url.contains("/checkUser") || "/jump".equals(url) || url.contains("/code") || url.contains("/resources/") || "/login".equals(url)){
            return true;
        }
        if(session.getAttribute("user")==null){
            response.sendRedirect("/jump");
            return false;
        }else{
            return true;
        }
    }
}
